import {ChangeDetectorRef, Component, EventEmitter, Input, Output} from '@angular/core';
import {NativeService} from '../../services/native.service';
import {Utils} from '../../services/Utils';
import {StorageService} from '../../services/storage.service';
import {API} from "../../services/API";


@Component({
    selector: 'app-filter-box',
    templateUrl: './filter-box.component.html',
    styleUrls: ['./filter-box.component.scss'],
})
export class FilterBoxComponent {
    @Input()
    filterData: Array<FilterData> = [];
    @Output()
    getSubmitData = new EventEmitter<any>();
    submitData;
    endTime = '';
    begin;
    end;
    constructor(
        private  native: NativeService,
                private cd: ChangeDetectorRef,
        ) {
    }

    async ngOnInit() {
    }
    // 选择该item
    onSelect(item: FilterData,i) {
        item.isSelect = !item.isSelect;
        for (let j = 0; j < this.filterData.length; j++) {
            if (i === j) {
                this.submitData = item.id;
                item.isSelect = true;
            } else {
                this.filterData[j].isSelect = false;
            }
        }
        this.getSubmitData.emit(this.submitData);
        this.cd.detectChanges();
    }

    onTouchMove(e) {
        e.preventDefault();
        this.cd.detectChanges();
    }
}

export interface FilterData {
    id: string;
    content: string;
    isSelect?: boolean;
}
